package com.lh.shop.runner;

import com.lh.common.domain.Shop;
import com.lh.shop.service.EsService;
import com.lh.shop.service.ShopService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @ClassName：EsApplicationRunner
 * @Author: LeiHao
 * @Date: 2024/8/9 19:48
 * @Description: 必须描述类做什么事情, 实现什么功能
 */
@Component
@Log4j2
public class EsApplicationRunner implements ApplicationRunner {

    @Autowired
    private ShopService shopService;
    @Autowired
    private EsService esService;
    @Override
    public void run(ApplicationArguments args) throws Exception {
        List<Shop> list = shopService.findAll();
        if (!CollectionUtils.isEmpty(list)){
            esService.bulkInsert(list);
            log.info("es同步成功");
            return;
        }
        log.error("es同步失败");
    }
}
